package net.zjitc.arrays;

import java.util.ArrayList;
import java.util.List;

public class TriMat {
    private int row;//矩阵行
    private int col;//列
    private int count; //个数
    private List<Triple> list;//三元组元素


    public TriMat() {
        list = new ArrayList<>();
    }

    public TriMat(int row, int col, List<Triple> list) {
        this.row = row;
        this.col = col;
        this.list = list;
    }

    public TriMat(int row, int col) {
        this.row = row;
        this.col = col;
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public int getCol() {
        return col;
    }

    public void setCol(int col) {
        this.col = col;
    }

    public List<Triple> getList() {
        return list;
    }

    public void setList(List<Triple> list) {
        this.list = list;
    }

    //

    public void creatMat(int[][] arr){
      row = arr.length;
      col = arr[0].length;

      //遍历矩阵元素找非零值，存储到三元组集合中
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length ; j++) {
              if (arr[i][j] != 0){
                  list.add( new Triple(i,j,arr[i][j]));
                  count++;
              }
            }
        }

    }

    public int getCount() {
        return count;
    }
}
